﻿using BCCommon.TMS.Transport;
using BCDto.TMS.Agent.AgentAreaRecord;
using BCDto.TMS.EasyMoveSuiteConfig;
using BCDto.TMS.VehicleSuiteBusinessConfig;
using BCDto.TMS.WorryFreeMoveSuiteConfig;
using BCService.TMS.EasyMoveSuiteConfig;
using BCService.TMS.VehicleSuiteBusinessConfig;
using BCService.TMS.WorryFreeMoveSuiteConfig;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.ClientApp.VehicleSuiteBusiness
{
    /// <summary>
    /// 车辆套餐业务配置
    /// </summary>
    [Route("api/v1/ClientApp/[controller]")]
    [ApiExplorerSettings(GroupName = "ClientApp")]
    [AllowAnonymous]
    public class VehicleSuiteBusinessConfigController : ClientAppBaseController
    {
        private readonly IVehicleSuiteBusinessConfigService vehicleSuiteBusinessConfigService;
        private readonly IWorryFreeMoveSuiteConfigService worryFreeMoveSuiteConfigService;
        private readonly IEasyMoveSuiteConfigService easyMoveSuiteConfigService;
        public VehicleSuiteBusinessConfigController(IVehicleSuiteBusinessConfigService vehicleSuiteBusinessConfigService,
            IWorryFreeMoveSuiteConfigService worryFreeMoveSuiteConfigService,
            IEasyMoveSuiteConfigService easyMoveSuiteConfigService)
        {
            this.vehicleSuiteBusinessConfigService = vehicleSuiteBusinessConfigService;
            this.worryFreeMoveSuiteConfigService = worryFreeMoveSuiteConfigService;
            this.easyMoveSuiteConfigService = easyMoveSuiteConfigService;
        }

        #region 获取车辆套餐业务配置列表
        /// <summary>
        ///  获取车辆套餐业务配置列表
        /// </summary>
        /// <param name="countyCode">区县编码</param>
        /// <param name="vehicleTransportBusinessConfigId">运输业务配置Id</param>
        /// <response code="200">获取车辆套餐业务配置列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{county_code}/{vehicle_transport_business_config_id}")]
        [ProducesResponseType(typeof(IEnumerable<VehicleSuiteBusinessConfigDto>), 200)]
        public IActionResult Get([FromRoute( Name ="county_code")]string countyCode,[FromRoute(Name = "vehicle_transport_business_config_id")]int vehicleTransportBusinessConfigId)
        {
            long? agentRecordId = this.GetAgentRecordIdByCountyCode(countyCode);
            return StatusCode((int)HttpStatusCode.OK, this.vehicleSuiteBusinessConfigService.GetList(agentRecordId,countyCode, vehicleTransportBusinessConfigId));
        }
        #endregion

        #region 获取套餐业务存在的区域树形列表
        /// <summary>
        ///  获取套餐业务存在的区域树形列表
        /// </summary>
        /// <param name="suiteBusinessType">套餐业务类型</param>
        /// <response code="200">获取套餐业务存在的区域树形列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]/{suite_business_type}")]
        [ProducesResponseType(typeof(IEnumerable<AgentAreaTreeDto>), 200)]
        public IActionResult SuiteTree([FromRoute(Name = "suite_business_type")] VehicleSuiteBusinessType suiteBusinessType)
        {
            if (suiteBusinessType == VehicleSuiteBusinessType.EasyMove)
            {
                return StatusCode((int)HttpStatusCode.OK, this.easyMoveSuiteConfigService.GetAgenAreaTreeList());
            }
            else
            {
                return StatusCode((int)HttpStatusCode.OK, this.worryFreeMoveSuiteConfigService.GetAgenAreaTreeList());
            }
        }
        #endregion

        #region 获取无忧搬家套餐业务配置列表
        /// <summary>
        ///  获取无忧搬家套餐业务配置列表
        /// </summary>
        /// <param name="countyCode">区县编码</param>
        /// <response code="200">获取无忧搬家套餐业务配置列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]/{county_code}")]
        [ProducesResponseType(typeof(IEnumerable<WorryFreeMoveSuiteConfigViewDto>), 200)]
        public IActionResult WorryFreeMoving([FromRoute(Name = "county_code")] string countyCode)
        {
            long? agentRecordId = this.GetAgentRecordIdByCountyCode(countyCode);
            if (!agentRecordId.HasValue)
            {
                throw new ArgumentException("当前区域并未开通无忧搬家套餐业务!");
            }
            return StatusCode((int)HttpStatusCode.OK, this.worryFreeMoveSuiteConfigService.GetList(agentRecordId.Value, countyCode));
        }
        #endregion

        #region 获取便捷搬家套餐业务配置列表
        /// <summary>
        ///  获取便捷搬家套餐业务配置列表
        /// </summary>
        /// <param name="countyCode">区县编码</param>
        /// <response code="200">获取便捷搬家套餐业务配置列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]/{county_code}")]
        [ProducesResponseType(typeof(IEnumerable<EasyMoveSuiteConfigViewDto>), 200)]
        public IActionResult EasyMoving([FromRoute(Name = "county_code")] string countyCode)
        {
            long? agentRecordId = this.GetAgentRecordIdByCountyCode(countyCode);
            if (!agentRecordId.HasValue)
            {
                throw new ArgumentException("当前区域并未开通便捷搬家套餐业务!");
            }
            return StatusCode((int)HttpStatusCode.OK, this.easyMoveSuiteConfigService.GetList(agentRecordId.Value, countyCode));
        }
        #endregion
    }
}
